/**
 * Created by dinghh on 2018-7-11.
 */
angular.module('MetronicApp').controller('ThinkTankController',
    ['$rootScope', '$scope', '$state', '$uibModal', 'toastr','$location','$stateParams', 'FileStorageService', 'ThinkTankService',
        function ($rootScope, $scope, $state, $uibModal, toastr,$location,$stateParams, FileStorageService, ThinkTankService) {
            $scope.$on('$viewContentLoaded', function () {
                App.initAjax();
                $rootScope.settings.layout.pageBodySolid = true;
                $rootScope.settings.layout.pageSidebarClosed = false;

                $scope.condition = {};
                $scope.typeList = [];

                //tab页切换
                $scope.tabItemList = [
                    {
                        "name": "环保智库",
                        "router": "thinkTank",
                        "selected": true
                    },
                    {
                        "name": "配置管理",
                        "router": "deploy",
                        "selected": false
                    },
                    {
                        "name": "统计",
                        "router": "statistics",
                        "selected": false
                    }
                ];

                $("#thinkTank li").click(function (e) {
                    //左边标签体系tab点击背景变色
                    $(this).addClass('selected');
                    $(this).siblings('li').removeClass('selected');
                    e.preventDefault();
                    var item = $(this).index();  //获取索引下标 也从0开始
                    ("下标索引值为：" + item );
                });

                //给左边标签体系tab增加点击事件，切换li标签内容
                $scope.changeTab=function (index) {
                    switch (index) {
                        case 0:
                            ThinkTankService.putSearchParams({
                                search: $scope.condition.search
                            });
                            ThinkTankService.getTimeNews().$promise.then(function (result) {
                                if("success" == result.status){
                                    $scope.news0 = result.data[0].data;
                                    $scope.news1 = result.data[1].data;
                                    $scope.news2 = result.data[2].data;
                                    $scope.news3 = result.data[3].data;
                                }else {
                                    for(var index in result.errors){
                                        toastr.error(result.errors[index].errmsg,"数据信息获取失败");
                                    }
                                }
                            });
                            break;
                        case 1:
                            ThinkTankService.putSearchParams({
                                search: $scope.condition.search
                            });
                            ThinkTankService.getIndustryNews().$promise.then(function (result) {
                                if("success" == result.status){
                                    $scope.news0 = result.data[0].data;
                                    $scope.news1 = result.data[1].data;
                                    $scope.news2 = result.data[2].data;
                                    $scope.news3 = result.data[3].data;
                                }else {
                                    for(var index in result.errors){
                                        toastr.error(result.errors[index].errmsg,"数据信息获取失败");
                                    }
                                }
                            });
                            break;
                        case 2:
                            ThinkTankService.putSearchParams({
                                search: $scope.condition.search
                            });
                            ThinkTankService.getPolicyNews().$promise.then(function (result) {
                                if("success" == result.status){
                                    $scope.news0 = result.data[0].data;
                                    $scope.news1 = result.data[1].data;
                                    $scope.news2 = result.data[2].data;
                                    $scope.news3 = result.data[3].data;
                                }else {
                                    for(var index in result.errors){
                                        toastr.error(result.errors[index].errmsg,"数据信息获取失败");
                                    }
                                }
                            });
                            break;
                        case 3:
                            ThinkTankService.putSearchParams({
                                search: $scope.condition.search
                            });
                            ThinkTankService.getDistrictNews().$promise.then(function (result) {
                                if("success" == result.status){
                                    $scope.news0 = result.data[0].data;
                                    $scope.news1 = result.data[1].data;
                                    $scope.news2 = result.data[2].data;
                                    $scope.news3 = result.data[3].data;
                                }else {
                                    for(var index in result.errors){
                                        toastr.error(result.errors[index].errmsg,"数据信息获取失败");
                                    }
                                }
                            });
                            break;
                    }
                };

                //获取数据
                ThinkTankService.getTimeNews().$promise.then(function (result) {
                    if("success" == result.status){
                        $scope.news0 = result.data[0].data;
                        $scope.news1 = result.data[1].data;
                        $scope.news2 = result.data[2].data;
                        $scope.news3 = result.data[3].data;
                    }else {
                        for(var index in result.errors){
                            toastr.error(result.errors[index].errmsg,"数据信息获取失败");
                        }
                    }
                });


            });
        }
    ]
);